﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
///OpinionDao 的摘要说明
/// </summary>
public class OpinionDao
{
    DBMM dbm = new DBMM();
    DataTable dt = null;
    string sql = null;
    OpinionVo ov = new OpinionVo();

    //添加留言
    public Exception addOpinion(OpinionVo ov)
    {
        sql = "insert into Opinion values(@Ocontent,@Otime,@Uid,@Oauthor,@Id,@Otype)";
        SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@Ocontent", ov.Ocontent), 
                                                 new SqlParameter("@Otime", DateTime.Now.ToString()), 
                                                 new SqlParameter("@Uid", ov.Uid), 
                                                 new SqlParameter("@Oauthor", ov.Oauthor), 
                                                 new SqlParameter("@Id", ov.Id),
                                                 new SqlParameter("@Otype",ov.Otype)};
        Exception ex = null;
        ex = dbm.Execute(sql, sp);
        return ex;
    }

    //删除留言
    public Exception delOpinion(string id)
    {
        sql = "delete Opinion where Oid=@Oid";
        SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@Oid", id) };
        Exception ex = null;
        ex = dbm.Execute(sql, sp);
        return ex;
    }

    //查找相关留言
    public DataTable getOpinion(string id, string type)
    {
        sql = "select * from Opinion where Id=@Id and Otype=@Otype order by Oid desc";
        SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@Id", id),
                                                 new SqlParameter("@Otype", type)};
        dt = new DataTable();
        dt = dbm.GetTable(sql, sp);
        return dt;
    }

    //查找站长留言
    public DataTable getMasterOpinion()
    {
        sql = "select * from Opinion where Id=0 order by Oid desc";
        dt = new DataTable();
        dt = dbm.GetTable(sql);
        return dt;
    }
}
